package com.zf.spring.batch;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

public class CustomItemRead implements ItemReader<String> {

	private static final int MAX_OUTER = 0;

	// 假定数据源是这个字符串数组
	private String[] input = { "Hello", "world!", "Wow", "that's", "cool!" };

	private int index = 0;

	private int outer = 0;

	@Override
	public String read() throws Exception, UnexpectedInputException,
			ParseException, NonTransientResourceException {
		if (index >= input.length) {
			outer++;
			if (outer > MAX_OUTER) {
				return null;
			} else {
				index = 0;
			}
		}
		return input[index++];
	}

}
